package com.gulimall.search.web;

import java.util.concurrent.*;

/**
 * @author coder_ccy
 * @date 2022/3/30 11:16
 */
public class Demo1 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        Thread thread1 = new Thread(new Thread() {
//            @Override
//            public void run() {
//                System.out.println("thread1");
//            }
//        });
//
//        thread1.start();// 启动线程
//
//        Runnable runnable =  new Runnable(){
//            @Override
//            public void run() {
//                System.out.println(Thread.currentThread().getName()+" is running");
//            }
//        };
//        new Thread(runnable).start();

//        FutureTask<Object> futureTask = new FutureTask<>(new Callable<Object>() {
//            @Override
//            public Object call() throws Exception {
//                return "callable";
//            }
//        });
//        new Thread(futureTask).start();
//
//        System.out.println("主线程运行中.......");
//
//        System.out.println(futureTask.get());

        // 上面叫内存泄露，什么叫内存溢出   static  gc gcroot根    栈溢出  堆溢出
        // 系统提供的线程池都不用？  maximumPoolSize 默认是无限大的，如果在线上，容易导致，资源泄露  oom

        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(
                5,
                200,
                10,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(10000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );

        poolExecutor.execute(()->{   // 函数式接口
            System.out.println("线程池");

        });

        poolExecutor.shutdown();//关闭线程池

    }
}
